package com.zmj.sy.mom.srv.aps.utils;

import com.zmj.sy.mom.srv.aps.bean.bo.ApsSchedulingFactoryCacheBo;
import com.zmj.sy.mom.srv.aps.bean.bo.ApsSchedulingOrderCacheBo;
import com.zmj.sy.mom.srv.aps.bean.entity.order.ApsOrder;
import com.zmj.sy.mom.srv.aps.bean.entity.order.Order;
import org.springframework.stereotype.Component;

import java.util.Comparator;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Component
public class ApsSchedulingStrategy {

    public void scheduling(ApsSchedulingOrderCacheBo orderCache, ApsSchedulingFactoryCacheBo apsFactoryCache) {

        // 1.排序好所有的包，然后分配优先级
        orderCache.getOrderList().sort(Comparator.comparing(Order::getSeq));
        Map<Integer, Order> orderIdMap = orderCache.getOrderList().stream().collect(Collectors.toMap(Order::getId, Function.identity()));

        orderCache.getApsOrderList().sort(Comparator.comparing((ApsOrder e) -> orderIdMap.get(e.getOrderId()).getSeq()).thenComparing(ApsOrder::getSeq));

        // 2.根据包，找到所有的拼装件，开始正排拼装件

    }
}
